
* 02-03, 03-04, 04-05, 05-06, 06-07, 07-08 school years
use "$data/calendar2003_2007.dta", clear
tolower CDS_CODE COMPUTER INTERNET CAL*
rename cal_con cal_concept6
rename cal_mod cal_modified
rename cal_cust cal_custom
rename cds_code cdscode
rename cal_sing cal_single
destring cdscode, replace

foreach num of numlist 2002/2007{
preserve
keep if year == `num'
keep cal* cdscode year

nsplit cdscode, digits(7)
	
rename cdscode cdscode_14dig
rename cdscode2 cdscode
rename cdscode1 cdscode_beg7

duplicates drop cdscode, force

compress
save calendar`num'.dta, replace
restore
}

* 08-09 school year
import delimited cbedsopus08b.txt, encoding(ISO-8859-1) clear
keep if section == "F" 			// pertains to school calendar
keep if value == "True"

gen modified = 1 if description == "Modified Concept"
bysort cdscode: egen cal_modified = max(modified)

gen custom = 1 if description == "Custom"
bysort cdscode: egen cal_custom = max(custom)

gen trad = 1 if description == "Traditional"
bysort cdscode: egen cal_trad = max(trad)

gen sing = 1 if description == "Single-Track"
bysort cdscode: egen cal_single = max(sing)

gen forty = 1 if description == "45/15"
bysort cdscode: egen cal_45_15 = max(forty)

gen sixty = 1 if description == "60/15"
bysort cdscode: egen cal_60_15 = max(sixty)

gen sixty1 = 1 if description == "60/20"
bysort cdscode: egen cal_60_20 = max(sixty1)

gen ninty = 1 if description == "90/30"
bysort cdscode: egen cal_90_30 = max(ninty)

gen multi = 1 if description == "Multitrack"
bysort cdscode: egen cal_mult = max(multi)

gen conc = 1 if description == "Concept 6"
bysort cdscode: egen cal_concept6 = max(conc)

foreach var of varlist cal* {
replace `var' = 0 if `var' == .
}

keep cal* cdscode year

nsplit cdscode, digits(7)
	
rename cdscode cdscode_14dig
rename cdscode2 cdscode
rename cdscode1 cdscode_beg7

duplicates drop cdscode, force

compress
save calendar2008.dta, replace


* 09-10 school year
import delimited cbedsora09b.txt, encoding(ISO-8859-1) clear
keep if section == "F" 			// pertains to school calendar
keep if level == "S"
drop if value == "FALSE"

gen modified = 1 if description == "Modified Concept"
bysort cdscode: egen cal_modified = max(modified)

gen custom = 1 if description == "Custom"
bysort cdscode: egen cal_custom = max(custom)

gen trad = 1 if description == "Traditional"
bysort cdscode: egen cal_trad = max(trad)

gen sing = 1 if description == "Single-Track"
bysort cdscode: egen cal_single = max(sing)

gen forty = 1 if description == "45/15"
bysort cdscode: egen cal_45_15 = max(forty)

gen sixty = 1 if description == "60/15"
bysort cdscode: egen cal_60_15 = max(sixty)

gen sixty1 = 1 if description == "60/20"
bysort cdscode: egen cal_60_20 = max(sixty1)

gen ninty = 1 if description == "90/30"
bysort cdscode: egen cal_90_30 = max(ninty)

gen multi = 1 if description == "Multitrack"
bysort cdscode: egen cal_mult = max(multi)

gen conc = 1 if description == "Concept 6"
bysort cdscode: egen cal_concept6 = max(conc)

foreach var of varlist cal* {
replace `var' = 0 if `var' == .
}

keep cal* cdscode year

nsplit cdscode, digits(7)
	
rename cdscode cdscode_14dig
rename cdscode2 cdscode
rename cdscode1 cdscode_beg7

duplicates drop cdscode, force

compress
save calendar2009.dta, replace


* 10-11 school year
import delimited cbedsora10b.txt, encoding(ISO-8859-1) clear
keep if section == "D" 			// pertains to school calendar

gen modified = 1 if description == "Modified Concept"
bysort cdscode: egen cal_modified = max(modified)

gen custom = 1 if description == "Custom"
bysort cdscode: egen cal_custom = max(custom)

gen trad = 1 if description == "Traditional"
bysort cdscode: egen cal_trad = max(trad)

gen sing = 1 if description == "Single-Track"
bysort cdscode: egen cal_single = max(sing)

gen forty = 1 if description == "45/15"
bysort cdscode: egen cal_45_15 = max(forty)

gen sixty = 1 if description == "60/15"
bysort cdscode: egen cal_60_15 = max(sixty)

gen sixty1 = 1 if description == "60/20"
bysort cdscode: egen cal_60_20 = max(sixty1)

gen ninty = 1 if description == "90/30"
bysort cdscode: egen cal_90_30 = max(ninty)

gen multi = 1 if description == "Multitrack"
bysort cdscode: egen cal_mult = max(multi)

gen conc = 1 if description == "Concept 6"
bysort cdscode: egen cal_concept6 = max(conc)

foreach var of varlist cal* {
replace `var' = 0 if `var' == .
}

keep cal* cdscode year

nsplit cdscode, digits(7)
	
rename cdscode cdscode_14dig
rename cdscode2 cdscode
rename cdscode1 cdscode_beg7

duplicates drop cdscode, force

compress
save calendar2010.dta, replace


* 11-12 school year
import delimited cbedsora11b.txt, encoding(ISO-8859-1) clear
rename v1 cdscode
rename v2 countyname
rename v3 districtname
rename v4 schoolname
rename v5 description
rename v6 level
rename v7 section
rename v8 rownumber
rename v9 value
rename v10 year
keep if section == "D" 			// pertains to school calendar
keep if level == "S"
drop if value == "FALSE"
gen cus = 1 if description == "Custom" | description == "Modified Concept"

drop if description == "Start Date" | description == "End Date" 

gen modified = 1 if description == "Modified Concept"
bysort cdscode: egen cal_modified = max(modified)

gen custom = 1 if description == "Custom"
bysort cdscode: egen cal_custom = max(custom)

gen trad = 1 if description == "Traditional"
bysort cdscode: egen cal_trad = max(trad)

gen sing = 1 if description == "Single-Track"
bysort cdscode: egen cal_single = max(sing)

gen forty = 1 if description == "45/15"
bysort cdscode: egen cal_45_15 = max(forty)

gen sixty = 1 if description == "60/15"
bysort cdscode: egen cal_60_15 = max(sixty)

gen sixty1 = 1 if description == "60/20"
bysort cdscode: egen cal_60_20 = max(sixty1)

gen ninty = 1 if description == "90/30"
bysort cdscode: egen cal_90_30 = max(ninty)

gen multi = 1 if description == "Multitrack"
bysort cdscode: egen cal_mult = max(multi)

gen conc = 1 if description == "Concept 6"
bysort cdscode: egen cal_concept6 = max(conc)

foreach var of varlist cal* {
replace `var' = 0 if `var' == .
}

keep cal* cdscode year
	
destring cdscode, replace
nsplit cdscode, digits(7)

rename cdscode cdscode_14dig
rename cdscode2 cdscode
rename cdscode1 cdscode_beg7

duplicates drop cdscode, force

compress
save calendar2011.dta, replace


* 12-13 school year
import delimited cbedsora12b.txt, encoding(ISO-8859-1) clear
keep if section == "D" 			// pertains to school calendar
keep if level == "S"
drop if value == "FALSE"

drop if description == "Start Date" | description == "End Date"
	
gen modified = 1 if description == "Modified Concept"
bysort cdscode: egen cal_modified = max(modified)

gen custom = 1 if description == "Custom"
bysort cdscode: egen cal_custom = max(custom)

gen trad = 1 if description == "Traditional"
bysort cdscode: egen cal_trad = max(trad)

gen sing = 1 if description == "Single-Track"
bysort cdscode: egen cal_single = max(sing)

gen forty = 1 if description == "45/15"
bysort cdscode: egen cal_45_15 = max(forty)

gen sixty = 1 if description == "60/15"
bysort cdscode: egen cal_60_15 = max(sixty)

gen sixty1 = 1 if description == "60/20"
bysort cdscode: egen cal_60_20 = max(sixty1)

gen ninty = 1 if description == "90/30"
bysort cdscode: egen cal_90_30 = max(ninty)

gen multi = 1 if description == "Multitrack"
bysort cdscode: egen cal_mult = max(multi)

gen conc = 1 if description == "Concept 6"
bysort cdscode: egen cal_concept6 = max(conc)

foreach var of varlist cal* {
replace `var' = 0 if `var' == .
}

keep cal* cdscode year

nsplit cdscode, digits(7)
	
rename cdscode cdscode_14dig
rename cdscode2 cdscode
rename cdscode1 cdscode_beg7
	
duplicates drop cdscode, force

compress
save calendar2012.dta, replace


* 13-14 school year
import delimited cbedsora13b.txt, encoding(ISO-8859-1) clear
keep if section == "D" 			// pertains to school calendar
keep if level == "S"
drop if value == "FALSE"
gen start = value if description == "Start Date"
gen end = value if description == "End Date"
destring start end, replace
bysort cdscode: egen start_date = max(start)
bysort cdscode: egen end_date = max(end)

drop if description == "Start Date" | description == "End Date"
	
gen modified = 1 if description == "Modified Concept"
bysort cdscode: egen cal_modified = max(modified)

gen custom = 1 if description == "Custom"
bysort cdscode: egen cal_custom = max(custom)


gen trad = 1 if description == "Traditional"
bysort cdscode: egen cal_trad = max(trad)

gen sing = 1 if description == "Single-Track"
bysort cdscode: egen cal_single = max(sing)

gen forty = 1 if description == "45/15"
bysort cdscode: egen cal_45_15 = max(forty)

gen sixty = 1 if description == "60/15"
bysort cdscode: egen cal_60_15 = max(sixty)

gen sixty1 = 1 if description == "60/20"
bysort cdscode: egen cal_60_20 = max(sixty1)

gen ninty = 1 if description == "90/30"
bysort cdscode: egen cal_90_30 = max(ninty)

gen multi = 1 if description == "Multitrack"
bysort cdscode: egen cal_mult = max(multi)

gen conc = 1 if description == "Concept 6"
bysort cdscode: egen cal_concept6 = max(conc)

foreach var of varlist cal* {
replace `var' = 0 if `var' == .
}

keep cal* cdscode year

nsplit cdscode, digits(7)
	
rename cdscode cdscode_14dig
rename cdscode2 cdscode
rename cdscode1 cdscode_beg7

duplicates drop cdscode, force

compress
save calendar2013.dta, replace


* 14-15 school year
import delimited cbedsora14b.txt, encoding(ISO-8859-1) clear
rename ïcdscode cdscode
keep if section == "D" 			// pertains to school calendar

gen start = value if description == "Start Date"
gen end = value if description == "End Date"
destring start end, replace
bysort cdscode: egen start_date = max(start)
bysort cdscode: egen end_date = max(end)

drop if description == "Start Date" | description == "End Date"
	
gen modified = 1 if description == "Modified Concept"
bysort cdscode: egen cal_modified = max(modified)

gen custom = 1 if description == "Custom"
bysort cdscode: egen cal_custom = max(custom)

gen trad = 1 if description == "Traditional"
bysort cdscode: egen cal_trad = max(trad)

gen sing = 1 if description == "Single-Track"
bysort cdscode: egen cal_single = max(sing)

gen forty = 1 if description == "45/15"
bysort cdscode: egen cal_45_15 = max(forty)

gen sixty = 1 if description == "60/15"
bysort cdscode: egen cal_60_15 = max(sixty)

gen sixty1 = 1 if description == "60/20"
bysort cdscode: egen cal_60_20 = max(sixty1)

gen ninty = 1 if description == "90/30"
bysort cdscode: egen cal_90_30 = max(ninty)

gen multi = 1 if description == "Multitrack"
bysort cdscode: egen cal_mult = max(multi)

gen conc = 1 if description == "Concept 6"
bysort cdscode: egen cal_concept6 = max(conc)

foreach var of varlist cal* {
replace `var' = 0 if `var' == .
}

keep cal* cdscode year

nsplit cdscode, digits(7)
	
rename cdscode cdscode_14dig
rename cdscode2 cdscode
rename cdscode1 cdscode_beg7

duplicates drop cdscode, force

destring year, replace
compress
save calendar2014.dta, replace

